#ifndef CONFIGURATION_CPP
#define CONFIGURATION_CPP

#include "configuration.h"

#include "globals.h"
#include <iostream>
#include <fstream>

CConfig::CConfig()
{
    m_res = std::make_pair(640,480);
    m_b_fullscreen = false;
    m_b_show_fps = false;
    m_menu_category = CConfig::TITLE_SCREEN;
}

CConfig::~CConfig()
{
}

const sf::Key::Code& CConfig::getRegularKey(const sf::Key::Code& key) const
{
    return key;
}

void CConfig::read(const std::string& file_name)
{
    std::ifstream cfg_ifs(file_name.c_str(), std::ios::in);
    if( !cfg_ifs )
    {
        std::cerr << "Could not read " << file_name << std::endl;
    }

    std::string current_line;

    // creation of buffer variables
    std::string s1;
    int w, h;

    while( getline(cfg_ifs,current_line) )
    {
        std::stringstream current_line_stream;
        current_line_stream << current_line;
        if ( !(current_line == "") )
        {
            switch ( current_line[0] )
            {
            case '#':
                // nothing to do since it is a comment line
            break;
            case 'r':
                // res _width_ _heigth_
                current_line_stream >> s1 >> w >> h;
                m_res = std::make_pair(w,h);
            break;
            case 'f':
                // f _0 or 1_
                current_line_stream >> s1 >> w;
                m_b_fullscreen = (w == 1);
            break;
            default:
            break;
            }
        } // end if
    } // end while
    // on ferme le fichier
    cfg_ifs.close();
}

void CConfig::save()
{
//    std::ofstream cfg_ofs();
}

void CConfig::messageToWrite()
{
//    double a, b;
//    std::ostringstream resolution;
//    resolution << "Resolution " << m_res;
//    a = ( 1.0 - resolution.size() ) / 2;
//    CEngine::Write(resolution.str(),0.0,1.0-0.05);
//    std::ostringstream fullscreen;
//    fullscreen << "Fullscreen " << m_b_fullscreen;
//    CEngine::Write(resolution.str(),0.0,1.0-0.05);
}

#endif // CONFIGURATION_CPP
